package com.example.io;

import java.io.FileInputStream;

public class Demo01FileInputStream {
    public static void main(String[] args) throws Exception {
        //1.指定文件
        FileInputStream fis = new FileInputStream("D:\\aaa.txt");
        //2.1读取文件--一个一个读
//        int date = 0;
//        //read的返回值是字符的ASCII值
//        while ((date = fis.read()) != -1) {
//            System.out.println((char) date);
//        }

        //2.2读取文件--以字符数组读取
        //fis.read(buf)返回值读到的字符个数
        //
        byte[] buf = new byte[1024];
        int count = 0;
        while ((count = fis.read(buf)) != -1) {
            System.out.println(new String(buf, 0, count));
            System.out.println("字节数为:" + count);
        }
        //3.关闭
        fis.close();
        System.out.println();
        System.out.println("执行完毕");
    }

}
